<?php
	//var_dump($_POST);
	echo '<br/>';
	//var_dump($_FILES);
	$fid = $_POST['fid'];//获得父类id
	$zbk = $_POST['zbk'];//获得子版块添加内容
	$img = $_FILES['img']['name'];//提取文件上传文件名
	if(empty($_POST['zbk'])){
		header('location:./zbk.php?id='.$fid);
		exit;
	}
	
	
	//判断error
	$error = $_FILES['img']['error'];
	//echo $error;
	switch($error){
		case 1:
		case 2:
			exit('文件过大系统不支持');
		break;
		case 4:
			exit('请选择一个文件');
		break;
		case 3:
		case 6:
		case 7:
			exit('系统内部有误');
		break;
	}
	//允许的mime类型
	$mimeArray = array('image/jpg','image/jpeg','image/png','image/gif');
	//判断mime类型
	$mime = $_FILES['img']['type'];
	if(!in_array($mime,$mimeArray)){
		exit('文件类型不符');
	}
	
	//允许的后缀名
	$infoArray = array('jpg','jpeg','png','gif');
	//判断后缀名
	$fileInfo = pathinfo($_FILES['img']['name']);
	$info = $fileInfo['extension'];
	if(!in_array($info,$fileInfo)){
		exit('文件后缀名不符');
	}
	//控制文件大小
	$fileSize = $_FILES['img']['size'];
	if($fileSize > 2000000){
		exit('文件过大换一个');
	}
	//判断临时文件是否通过post方法生成
	if(is_uploaded_file($_FILES['img']['tmp_name'])){
		move_uploaded_file($_FILES['img']['tmp_name'],'../../public/admin/images/main/'.$_FILES['img']['name']);
	}
	
	//链接数据库
	$con = mysqli_connect('localhost','root','www');
	mysqli_set_charset($con,'utf8');
	mysqli_select_db($con,'admin');
	$SQL = "insert into type (name,img,pid,path) values ('{$zbk}','{$img}',{$fid},'0-{$fid}')";
	mysqli_query($con,$SQL);
	if(mysqli_affected_rows($con) >= 1){
		//echo 'cg';
		header('location:./bankuailiebiao.php');
	}
		

?>